﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>热表专项计划统计看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .el-form-item__label {
      color: #fff;
    }

    .header-title {
      font-size: 24px !important;
    }

    .el-form-item {
      margin-bottom: 0 !important;
    }

    .chart-title {
      text-align: center;
      padding-top: 10px;
      color: #fff;
    }

    .chart {
      width: 100%;
      height: 80px;
      font-size: 40px;
      font-weight: bold;
      cursor: pointer;
      text-align: center;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <div class="parallelogram header-outer">
        <el-row>
          <el-col :span="7" style="padding-left: 35px;">
            <img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" />
          </el-col>
          <el-col :span="10" class="header-title">
            <div class="parallelogram header-inner">
              {{queryInfo.factoryname}}专项计划统计看板
            </div>
          </el-col>
          <el-col :span="7" class="currentTime" style="padding-right: 35px;font-size: 18px;">
            {{currentTime}}
          </el-col>
        </el-row>
      </div>

      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules"
        style="margin:10px 10px 0 10px;">
        <el-form-item label="要求完成时间:" prop="needfinishdate">
          <el-date-picker v-model="queryInfo.needfinishdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="项目来源:">
          <el-select v-model="queryInfo.itemresource" placeholder="请选择" clearable filterable style="width: 160px;">
            <el-option :key="'改善计划'" :label="'改善计划'" :value="'改善计划'"></el-option>
            <el-option :key="'培训计划'" :label="'培训计划'" :value="'培训计划'"></el-option>
            <el-option :key="'日清会任务'" :label="'日清会任务'" :value="'日清会任务'"></el-option>
            <el-option :key="'会议纪要'" :label="'会议纪要'" :value="'会议纪要'"></el-option>
            <el-option :key="'主计划风险'" :label="'主计划风险'" :value="'主计划风险'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="searchData">查询</el-button>
        </el-form-item>

        <el-form-item label="切换其他看板:">
          <el-select v-model="selectPageName" placeholder="请选择" filterable @change="reloadUrl">
            <el-option v-for="item in urlMap" :key="item.pagename" :label="item.name" :value="item.pagename">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <dv-border-box-10>
        <h3 class="chart-title">各责任单位完成情况</h3>
        <div class="chart" :style="{height: chartHeight + 'px'}" id="chart"></div>
      </dv-border-box-10>
    </div>

    <el-dialog :title="chartDetail.title" :width="'98%'" :top="'10px'" :center="'center'"
      :visible.sync="chartDetail.dialogVisiable">
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="chartDetail.dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-download" size="mini" @click="exportDetail">
              导出
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="项目来源" prop="itemresource"></el-table-column>
        <el-table-column label="项目内容" prop="itemcontent"></el-table-column>
        <el-table-column label="措施" prop="itemfinishprogress"></el-table-column>
        <el-table-column label="要求完成时间" prop="needfinishdate" :formatter="splitDate"></el-table-column>
        <el-table-column label="完成时间" prop="finishdate" :formatter="splitDate"></el-table-column>
        <el-table-column label="责任单位" prop="responseteam"></el-table-column>
        <el-table-column label="状态" prop="status">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === '未完成'" type="danger">{{scope.row.status}}</el-tag>
            <el-tag v-else-if="scope.row.status === '按时完成'" type="success">{{scope.row.status}}</el-tag>
            <el-tag v-else type="warning">{{scope.row.status}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="超期天数" prop="delayday"></el-table-column>
      </el-table>
      <el-pagination @current-change="handleChartDetailCurrentChange" :current-page="chartDetail.queryInfo.currentPage"
        :page-sizes="[chartDetail.queryInfo.pageSize]" :page-size="chartDetail.queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="chartDetail.total">
      </el-pagination>
    </el-dialog>

  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { exportExcelData, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        currentTime: '',
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: { factoryid: '', factoryname: '', needfinishdate: '', itemresource: '' },
        chartLoadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#FFF' },
        rules: { needfinishdate: [{ required: true, message: '要求完成时间不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] },
        chartHeight: (window.innerHeight - 200),
        chartDetail: {
          dialogVisiable: false,
          queryInfo: { currentPage: 1, pageSize: 12, seriesName: '', name: '' },
          dataList: [], title: '', total: 0
        },
        selectPageName: '',
        urlMap: [
          { name: '专项计划统计看板', pagename: 'RbSpecialItemPlanCountDashBoard' },
          { name: '齐套性检查趋势看板', pagename: 'RBCompleteSetRateChartDashBoard' },
          { name: 'APS排产统计看板', pagename: 'RbApsShipFinishDashBoardV2' },
          { name: '转工看板(生产作业会)', pagename: 'ContainerShipDashBoardSCB' },
        ]
      },
      methods: {
        searchData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) { return this.$message.error('必填项不能为空'); }
            this.getData();
          })
        },
        async getData() {
          const dom = document.getElementById("chart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.chartLoadingConfig);

          const { data: { data, meta, total } } = await axios.post('../handler/board/RbSpecialItemPlanCountDashBoard.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status == 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arr_responseteam = [], arr_finishrate = [], arr_intimerate = [], arr_notfinishrate = [], arr_delaydayssum = [];
          data.forEach(i => {
            arr_responseteam.push(i.responseteam);//责任单位
            arr_finishrate.push(i.finishrate);//完成率
            arr_intimerate.push(i.intimefinishrate);//按时完成率
            arr_notfinishrate.push(i.notfinishrate);//未完成率
            arr_delaydayssum.push(i.delaydays);//超期天数
          });

          let option = barOption();

          option.grid = { left: '3%', right: '3%', bottom: '5%', containLabel: true };
          option.yAxis[0].axisLabel.formatter = function (data) { return data + "%"; };//y轴文字追加%
          option.yAxis[1].axisLabel.formatter = function (data) { return data + '天' };//y轴文字追加%

          option.legend.data = ['完成率', '按时完成率', '未完成率', '超期天数'];//设置图例文字
          option.xAxis.data = arr_responseteam;

          option.series[0] = _.merge(option.series[0], {
            name: '完成率',
            data: arr_finishrate,
            barMaxWidth: 35,
            barGap: '80%',
            label: { color: colorList.green.color, formatter: '{c}%' },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '按时完成率',
            data: arr_intimerate,
            label: { color: colorList.lightGreen.color },
            itemStyle: { color: { colorStops: colorList.lightGreen.colorStops } }
          });

          option.series[2] = _.merge(_.cloneDeep(option.series[0]), {
            name: '未完成率',
            data: arr_notfinishrate,
            label: { color: colorList.red.color },
            itemStyle: { color: { colorStops: colorList.red.colorStops } }
          });

          option.series[3] = _.merge(_.cloneDeep(option.series[0]), {
            name: '超期天数',
            data: arr_delaydayssum,
            yAxisIndex: 1,
            label: { color: colorList.orange.color, formatter: '{c}天' },
            itemStyle: { color: { colorStops: colorList.orange.colorStops } }
          });

          chart.setOption(option);

          window.addEventListener('resize', () => {
            chart.resize();
          });

          chart.on('click', (params) => {
            const { seriesName, name, value } = params;
            if (value == 0) { return; }
            this.chartDetail.queryInfo.currentPage = 1;
            this.chartDetail.queryInfo.seriesName = seriesName;
            this.chartDetail.queryInfo.name = name;
            this.chartDetail.title = `【${name}】-【${seriesName}】明细`;
            this.chartDetail.dialogVisiable = true;
            this.getDetails();
          })
        },
        // 明细
        async getDetails() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/RbSpecialItemPlanCountDashBoard.ashx?action=getDetails', {
            type: 'getDetails',
            ...this.queryInfo,
            ...this.chartDetail.queryInfo,
            title: this.chartDetail.title
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.chartDetail.dataList = data;
          this.chartDetail.total = total;
        },
        handleChartDetailCurrentChange(newPage) {
          this.chartDetail.queryInfo.currentPage = newPage;
          this.getDetails();
        },
        // 导出
        exportDetail() {
          const config = {
            url: '../handler/board/RbSpecialItemPlanCountDashBoard.ashx?action=exportData',
            data: {
              type: 'exportData',
              ...this.queryInfo,
              ...this.chartDetail.queryInfo,
              title: this.chartDetail.title
            }
          }
          exportExcelData(config, this);
        },
        reloadUrl() {
          const pagename = this.selectPageName;
          let { origin, search } = window.location;
          const url = `${origin}/MESReport/kanban/${pagename}.html${search}`;
          location.href = url;
        }
      },
      async mounted() {
        window.addEventListener('resize', () => {
          this.chartHeight = (window.innerHeight - 200);
        });
        let incrementNumber = () => {
          setTimeout(incrementNumber, 1000);
          const weekDayText = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][dayjs().format('d')];
          this.currentTime = `${dayjs().format('YYYY年MM月DD日')} ${weekDayText} ${dayjs().format('HH:mm')}`;
        }
        setTimeout(incrementNumber, 500);
        const startOfThisMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfThisMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.needfinishdate = [startOfThisMonth, endOfThisMonth];
        const factoryid = Decrypt(getParams('factoryid'));
        this.queryInfo.factoryid = factoryid;
        const factoryInfo = await getFactory({ factoryid });
        if (factoryInfo) {
          const { factoryname } = factoryInfo[0];
          this.queryInfo.factoryname = factoryname;
          document.title = `${factoryname}专项计划统计看板`;
        }
        this.searchData();
      }
    })
  </script>
</body>

</html>